#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 2e3 + 10, mod = 1e9 + 7;

ll n, m;
string s;
char offset = '0';
ll tr[N][10], fail[N], ed[N], idx;

void insert(const string& s)
{
    ll p = 0, i = 0;
    for (auto it : s) {
        ll c = it - offset;
        if (tr[p][c] == 0) tr[p][c] = ++idx;
        p = tr[p][c];
    }
    ed[p] = 1;
}

void setfail()
{
    queue<ll> q;
    for (ll i = 0;i < 10;i++) if (tr[0][i]) { q.push(tr[0][i]); }
    while (!q.empty()) {
        ll now = q.front();q.pop();
        for (ll i = 0;i < 10;i++) {
            if (tr[now][i]) {
                fail[tr[now][i]] = tr[fail[now]][i];
                ed[tr[now][i]] |= ed[fail[tr[now][i]]];
                q.push(tr[now][i]);
            } else tr[now][i] = tr[fail[now]][i];
        }
    }
}

ll f[N][N][2][2];

ll dfs(ll pos, ll p, ll lead, ll limit)//是否有前导0，是否受前缀限制
{
    if (pos == 0) return lead == 0 && ed[p] == 0;
    if (f[pos][p][lead][limit] != -1) return f[pos][p][lead][limit];
    ll up = limit ? s[pos] - '0' : 9, res = 0;
    for (ll i = 0;i <= up;i++) {
        if (ed[tr[p][i]]) continue;
        if (i == 0 && lead) (res += dfs(pos - 1, 0, lead && i == 0, limit && i == s[pos] - '0')) %= mod;
        else (res += dfs(pos - 1, tr[p][i], lead && i == 0, limit && i == s[pos] - '0')) %= mod;
    }
    f[pos][p][lead][limit] = res;
    return res;
}

void solve()
{
    cin >> s >> n;m = s.length();
    for (ll i = 1;i <= n;i++) {
        string c;cin >> c;
        insert(c);
    }
    setfail();

    reverse(s.begin(), s.end());
    s = " " + s;
    memset(f, -1, sizeof f);
    cout << dfs(m, 0, 1, 1);
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}